package org.blogwu.learn.multithread.chapter3.demo7;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchTest extends Thread {
    static CountDownLatch countDownLatch = new CountDownLatch(5);

    public CountDownLatchTest(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(getName() + " 开始进行启动检查");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(getName() + " 检查完毕");
        countDownLatch.countDown();
    }

    public static void main(String[] args) throws InterruptedException {
        Thread[] cz = new Thread[10];
        for (int i = 0; i < 10; i++) {
            cz[i] = new CountDownLatchTest("线程" + i);
        }
        for (int i = 0; i < 10; i++) {
            cz[i].start();
        }
        System.out.println("等待其他线程检查完毕");
        CountDownLatchTest.countDownLatch.await();
        System.out.println("检查完毕,开始启动");
    }
}
